<!DOCTYPE html>
<html lang="en" xmlns:v-bind="http://www.w3.org/1999/xhtml">
<head>
    <title>申购详情</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="Cache-Control" content="no-store, must-revalidate">
    <meta http-equiv="expires" content="Wed, 26 Feb 1997 08:21:57 GMT">
    <meta http-equiv="expires" content="-1">
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"
          name="viewport">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="shortcut icon" href="/dist/img/icon.png" type="image/x-icon">
    <link rel="shortcut icon" href="/dist/img/icon.png" type="image/x-icon">
    <!-- Bootstrap 3.3.6 -->
    <link rel="stylesheet" href="/dist/plugins/bootstrap/css/bootstrap.min.css">
    <!--字体-->
    <link rel="stylesheet" href="/dist/css/font-awesome.min.css">
    <!--图标-->
    <link rel="stylesheet" href="/dist/css/ionicons.min.css">
    <!--插件样式-->
    <link href="/dist/plugins/ztree/css/zTreeStyle/zTreeStyle.css" rel="stylesheet"/>
    <link rel="stylesheet" href="/dist/plugins/webuploader-0.1.5/webuploader.css">
    <!--OA主样式-->
    <link rel="stylesheet" href="/dist/css/OA.min.css?t=f5a12a1d">
    <link rel="stylesheet" href="/dist/css/skins/OA-skins.min.css?t=16f1e6f3">
    <style>
        select {
            background: transparent;
            border: none;
            outline: none;
        }

        .model-picker-input {
            opacity: 0 !important;
            top: -9999px;
            left: -9999px;
            position: absolute;
        }

        .model-picker-span {
            position: relative;
            display: block;
            outline: 0;
            -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
            border-bottom: 1px solid #ccc;
            background-color: #fff;
            color: #ccc;
            cursor: pointer;
        }

        .model-picker-span > .placeholder {
            color: #aaa;
        }

        .model-picker-span > .arrow {
            position: absolute;
            top: 50%;
            right: 8px;
            width: 10px;
            margin-top: -3px;
            height: 5px;
            background: url(../images/drop-arrow.png) -10px -25px no-repeat;
        }

        .model-picker-span.focus,
        .model-picker-span.open {
            border-bottom-color: #46A4FF;
        }

        .model-picker-span.open > .arrow {
            background-position: -10px -10px;
        }

        .model-picker-span > .title > span {
            color: #333;
            padding: 5px;
            border-radius: 3px;
        }

        .model-picker-span > .title > span:hover {
            background-color: #f1f8ff;
        }

        .model-picker-dropdown {
            position: absolute;
            width: 315px;
            left: -9999px;
            top: -9999px;
            outline: 0;
            -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
            z-index: 999999;
            display: none;
            min-width: 200px;
            margin-bottom: 20px;
            margin-top: 5px;
        }

        .model-select-wrap {
            box-shadow: 0 1px 5px rgba(0, 0, 0, 0.5);
        }

        .model-select-tab {
            border-bottom: 1px solid #ccc;
            background: #f5f5f5;
            /*font-size: 13px;*/
        }

        .model-select-tab > a {
            display: inline-block;
            padding: 4px 20px;
            border-left: 1px solid #ccc;
            border-bottom: 1px solid transparent;
            color: #4D4D4D;
            text-align: center;
            outline: 0;
            text-decoration: none;
            cursor: pointer;
            /*font-size: 14px;*/
            margin-bottom: -1px;
        }

        .model-select-tab > a.active {
            background: #fff;
            border-bottom: 1px solid #fff;
            color: #46A4FF;
        }

        .model-select-tab > a:first-child {
            border-left: none;
        }

        .model-select-tab > a:last-child.active {
            border-right: 1px solid #ccc;
        }

        .model-select-content {
            width: 100%;
            min-height: 50px;
            background-color: #fff;
            padding: 5px 5px;
        }

        .model-select dl {
            line-height: 2;
            clear: both;
            padding: 3px 0;
            margin: 0;
            max-height: 200px;
            overflow-y: scroll;
        }

        .model-select dt {
            position: absolute;
            width: 2.5em;
            font-weight: 500;
            text-align: right;
            line-height: 2;
        }

        .model-select dd {
            margin-left: 0;
            line-height: 2;
        }

        .model-select.province dd {
            margin-left: 3em;
        }

        .model-select a {
            display: inline-block;
            padding: 0 10px;
            outline: 0;
            text-decoration: none;
            white-space: nowrap;
            margin-right: 2px;
            color: #333;
            cursor: pointer;
        }

        .model-select a:hover,
        .model-select a:focus {
            background-color: #f1f8ff;
            border-radius: 2px;
            color: #46A4FF;
        }

        .model-select a.active {
            background-color: #46A4FF;
            color: #fff;
            border-radius: 2px;
        }

        .table-detail input[type=text] {
            padding-left: 0;

        }

        td {
            color: #2a8cec;
        }

        td.td-title, td select, td .filename, td.td-module {
            color: #333;
        }

        select {
            color: rgb(42, 140, 236) !important;
            background: #fff;
        }

        .table-detail td {
            /*font-size: 16px;*/
            line-height: 35px;
            height: 35px;
            border-right: 1px solid #cbcbcb;
            border-bottom: 1px solid #cbcbcb;
        }

        .table-detail td.td-title {
            line-height: 1.5;
            background: #F5F5F5;
        }

        .table-detail td.td-row3 {
            height: 70px;
            line-height: 20px;
            max-height: 70px;
            overflow: hidden;
            position: relative;
        }

        .yuying {
            position: absolute;
            right: 10px;
            bottom: 10px;
            width: 20px;
            height: 20px;
            background: url("/dist/img/yuyin.png");
            background-size: cover;
            cursor: pointer;
        }

        input {
            text-align: left !important;
        }

        .table-detail td.td-value {
            text-align: left !important;
            padding-left: 4px !important;
            /*font-size: 16px !important;*/
        }

        .btn-group-xs > .btn, .btn-xs {
            padding: 1px 5px;
            /*font-size: 16px;*/
            line-height: 1.5;
            border-radius: 3px;
        }

        .table-detail textarea {
            height: 60px;
            width: 100%;
            border: none;
            outline: none;
            -webkit-appearance: none;
            resize: none;
            line-height: 20px;
            padding-top: 2px !important;
            padding-left: 6px;
        }

        .td-row3 span {
            max-height: 60px;
            line-height: 20px;
            overflow: hidden;
            text-overflow: ellipsis;
            display: -webkit-box;
            -webkit-box-orient: vertical;
            -webkit-line-clamp: 3;
            text-align: left;

        }

        .div-td-content-more {
            position: absolute;
            height: auto;
            z-index: 999;
            line-height: 20px;
            background-color: #d3e8fd;
            padding: 8px 6px;
            border: 1px solid #e8e8ea;
            display: none;
        }

        .div-td-content-more i {
            width: 15px;
            height: 12px;
            background: url("/dist/img/more-icon.png");
            position: absolute;
            left: 50px;
            top: -12px;
        }

        .td-module td {
            color: black;
            font-weight: bold;
            background: yellow;
        }

        .table-detail {
            border-left: 1px solid #cbcbcb;
            border-top: 1px solid #cbcbcb;
        }

        .table-detail .td-module {
            background-color: yellow;
        }

        span.lineOne {
            line-height: 20px;
            height: 20px;
            overflow: hidden;
            text-overflow: ellipsis;
            display: -webkit-box;
            -webkit-box-orient: vertical;
            -webkit-line-clamp: 1;
        }

        .table-detail td.td-value2 {
            padding: 1px !important;
            text-align: left !important;
        }

        .td-value2 input {
            box-shadow: inset 1px 1px 4px #333;
            height: 100% !important;
            padding-left: 4px !important;
        }

        .span-a-btn {
            position: absolute;
            right: 10px;
        }

        .table-detail td.td-value {
            text-align: left !important;
            padding-left: 4px !important;
            /*font-size: 16px !important;*/
        }

        .jiaobiao3 {
            position: relative;
        }

        .jiaobiao3 i {
            display: block;
            width: 10px;
            height: 10px;
            background: url("/dist/img/newLog3.png");
            position: absolute;
            top: 0px;
            right: 0px;
        }

        .moreListData {
            position: absolute;
            top: 30px;
            z-index: 111;
            display: none;
        }

        .moreListData .item {
            width: 100%;
            height: 30px;
            line-height: 30px;
        }

        .moreListData .item span {
            margin-right: 5px;
        }

        .ui_main {
            vertical-align: top;
        }

        .table-detail input[type=text], .table-detail input[type=number], .table-detail input[type=tel], .table-detail select {
            margin-left: 0px;
            margin-right: 0px;
        }

        .user {
            height: 30px;
            line-height: 30px;
            max-height: 30px;
            float: left;
            text-align: left;
            min-width: 32px;
            padding-left: 1px;
            overflow: hidden;
            cursor: pointer;
        }

        .user:hover {
            background-color: #cfd4d1;
        }

        .userbox .select.user {
            color: #fff;
            background-color: #045B9E;
        }

        .span-btn {
            position: absolute;
            left: 10px;
            margin-top: 4px;
            cursor: pointer;
        }

        .auditorName {
            text-align: center !important;
        }


        .progressobj {
            height: 20px;
        }

        .progressobj .delfile {
            float: left;
            margin-left: 10px;
        }

        .select {
            color: #fff;
            background-color: #045B9E;
        }

        td .sp-value {
            display: inline-block;
            padding-left: 6px;
            word-wrap: break-word;
        }

        td {
            color: #2a8cec;
        }

        td.td-title, td select, td .filename, td.td-module {
            color: black;
            font-weight: normal !important;
        }

        .table-detail-payee:nth-child(even) td.td-title {
            background-color: white;
        }

        .printDiv {
            display: none;
        }

        .webuploader-pick {
            background: url(/dist/img/fjT1.png) no-repeat 5px center;
            display: block;
            padding: 0 4px;
            height: 22px;
            line-height: 22px;
            padding-left: 15px;
            margin: 0 auto;
            width: 70px;
            margin-top: 6px;
            border-radius: 4px;
        }

        .webuploader-pick-hover {
            color: #fff !important;
            background: url(/dist/img/fjT2.png) no-repeat 5px center;
            background-color: #0F6099;

        }
        td .lookFj {
            width: 100%;
            color: #2a8cec;
            overflow: hidden;
            text-overflow: ellipsis;
            display: -webkit-box;
            -webkit-box-orient: vertical;
            -webkit-line-clamp: 1;
            position: relative;
            cursor: pointer;
            padding-left: 4px;
            text-align: left;
        }
        .fj {
            color: #ddd;
            padding: 0 2px;
            background: url(/dist/img/fujian2.png) no-repeat 6px center;
            cursor: no-drop;
            display: inline-block;
            padding-left: 25px;
            height: 100%;
        }
        .divUploadedFiles .fj-tanzhongStyle {
            float: left;
            width: 300px;
            margin-top: 2px;
            overflow: hidden;
        }
    </style>
</head>
<body>
<iframe id="ifAttach" style="display:none"></iframe>
<div class="layout" style="left:0px;top:0px;right:0px;bottom:0px;" id="app">
    <!--<h4 class="text-center">行政物品申请</h4>-->
    <div class="center" style="padding-left:8px;padding-right:8px;">
        <table class="table-detail">
            <tr class="td-module">
                <td colspan="4">基本信息</td>
            </tr>
            <tr>
                <td class="td-title" style="width: 25%;">申购日期</td>
                <td class="td-tanZongStyle" style="width: 25%;">
                    <span style="padding-left: 4px;">{{purchase.main.applyDate}}</span>
                </td>
                <td class="td-title" style="width: 25%;">申购人</td>
                <td class="td-tanZongStyle" style="width: 25%;">
                    <span style="padding-left: 4px;">{{purchase.main.createUserName}}</span>
                </td>
            </tr>
            <tr>
                <td class="td-title" style="width: 25%;">公司</td>
                <td class="td-tanZongStyle" style="width: 25%;">
                    <span style="padding-left: 4px;">{{purchase.main.companyName}}</span>
                </td>
                <td class="td-title" style="width: 25%;">采购方式</td>
                <td class="td-tanZongStyle" style="width: 25%;">
                    <select v-model="purchase.main.method" v-if=" pageType=='edit' && type != 'buy' " class="validators">
                        <option selected value=""></option>
                        <option v-for="(item,i) in purchaseList" v-bind:value="item.value">
                            {{item.name}}
                        </option>
                    </select>
                    <span v-else style="padding-left: 4px;">{{purchase.main.method}}</span>
                </td>
            </tr>
            <tr>
                <td class="td-title" style="width: 25%;">要求到货时间</td>
                <td class="td-tanZongStyle" style="width: 25%;">
                    <input type="text" v-model="purchase.main.receiveDate" v-if="pageType=='edit' && type != 'buy'"
                           @focus="showDatePicker($event)" placeholder="请选择时间"/>
                    <span v-else style="padding-left: 4px;">{{purchase.main.receiveDate}}</span>
                </td>
                <td class="td-title" style="width: 25%;">采购用途</td>
                <td class="td-tanZongStyle" style="width: 25%;">
                    <input type="text" v-if="pageType=='edit' && type != 'buy'" v-model="purchase.main.purpose" class="validators"
                           placeholder="请输入"/>
                    <span v-else style="padding-left: 4px;">{{purchase.main.purpose}}</span>
                </td>
            </tr>
        </table>
        <table class="table-detail" >
            <tr class="td-module">
                <td colspan="4">商品信息
                    <span class="span-a-btn" v-if="pageType=='edit'">
                            <a href="javascript:void(0);" class="a-btn"
                               @click="addItem('goodsInfo','Goods')">添加商品</a>
                        <a href="javascript:void(0);" class="a-btn"
                           @click="delItem('goodsInfo')">删除商品</a>
                        </span>
                </td>
            </tr>
        </table>
        <table class="table-detail" v-for="(info,i) in purchase.goodsInfo">
            <tr>
                <td class="td-title" style="width: 25%;">物品名称</td>
                <td class="td-tanZongStyle" style="width: 25%;">
                    <select v-model="info.goodsName" v-if="pageType=='edit' && type != 'buy'" id="goodsName" @click="changeGoods(info)">
                        <option selected value=""></option>
                        <option v-for="(item,i) in myGoodsList" v-bind:value="item.goodsName" >
                            {{item.goodsName}}
                        </option>
                    </select>
                    <span v-else style="padding-left: 4px;">{{info.goodsName}}</span>
                </td>
                <td class="td-title" style="width: 25%;">单位</td>
                <td class="td-tanZongStyle" style="width: 25%;">
                    <input type="text" v-if="pageType=='edit' && type != 'buy'" v-model="info.unit" class="validators"
                           placeholder="请输入"/>
                    <span v-else style="padding-left: 4px;">{{info.unit}}</span>
                </td>
            </tr>
            <tr>
                <td class="td-title" style="width: 25%;">数量</td>
                <td class="td-tanZongStyle" style="width: 25%;">
                    <input type="text" v-if="pageType=='edit' && type != 'buy'" v-model="info.count" class="validators"
                           placeholder="请输入"/>
                    <span v-else style="padding-left: 4px;">{{info.count}}</span>
                </td>
                <td class="td-title" style="width: 25%;">单价(元)</td>
                <td class="td-tanZongStyle" style="width: 25%;" >
                    <input type="text" v-if="pageType=='edit' && type != 'buy'" v-model="info.price" class="validators"
                           placeholder="请输入"/>
                    <span v-else style="padding-left: 4px;">{{info.price}}</span>
                </td>
            </tr>
            <tr>
                <td class="td-title" style="width: 25%;">物品描述</td>
                <td class="td-tanZongStyle" style="width: 25%;" colspan="3">
                    <input type="text" v-if="pageType=='edit' && type != 'buy'" v-model="info.requirements" class="validators"
                           placeholder="请输入"/>
                    <span v-else style="padding-left: 4px;">{{info.requirements}}</span>
                </td>
            </tr>
            <tr v-for="(item,i2) in info.extraList">
                <td class="td-title" style="width: 25%;">{{item.title}}</td>
                <td class="td-tanZongStyle"  colspan="3">
                    <input type="text" v-if="pageType=='edit' && type != 'buy'" v-model="item.value"
                           placeholder="请输入"/>
                    <span v-else style="padding-left: 4px;">{{item.value}}</span>
                </td>
            </tr>
        </table>
        <!--审批进度-->
        <table class="table-detail no-print" style="border-top-width:0px;">
            <tr>
                <td class=" td-module" colspan="5" style="background: yellow;">审批进度</td>
            </tr>
            <tr>
                <td class="td-title" style="width:16%;">审核顺序</td>
                <td class="td-title" style="width:17%;">审核人员</td>
                <td class="td-title" style="width:16%;">审核状态</td>
                <td class="td-title" style="width:17%;">审核时间</td>
                <td class="td-title">审核意见</td>
            </tr>
            <tr v-for="(item,i) in purchase.auditors">
                <td>
                    <span v-if="pageType=='edit' && type == 'add'" class="span-btn">
                        <span style="font-size:20px;"
                              @click="addItem('auditors','Audit')"> + </span>
                        <span style="font-size:20px;"
                              @click="delItem('auditors',i,'审核人')"> - </span>
                    </span>
                    <span>第{{i+1}}审核人</span>
                </td>
                <td>
                    <input v-if="pageType=='edit'" class="auditorName" type="text"
                           :value="item.auditorName" :idx="i"/>
                    <span v-else>{{item.auditorName}}</span>
                </td>
                <td>
                    <span v-if="item.auditFlag==0" style="color:red;">{{convertAuditFlagToName(item.auditFlag)}}</span>
                    <span v-else>{{convertAuditFlagToName(item.auditFlag)}}</span>
                </td>
                <td>{{item.auditTime}}</td>
                <td><input type="text" v-model="item.auditAdvise"/></td>
            </tr>
        </table>
        <!--抄送人 和  付款人-->
        <table class="table-detail" style="border-top-width:0px;margin-bottom:20px;">
            <tr class="printDiv">
                <td class="td-title " style="width:16%;">审核人</td>
                <td class="" colspan="5">
                    <div v-for="(item,i) in purchase.auditors" class="user">{{item.auditorName}};
                    </div>
                </td>
            </tr>
            <tr>
                <td class="td-title" style="width:20%;">抄送人</td>
                <td colspan="5">
                    <div id="user" style="padding-left:6px;"
                         v-on:click.stop="inputFocus('txtCopier')">
                        <div v-for="(user,i) in purchase.copiers" class="user"
                             v-bind:class="{ select: copierSelectedIdx == i }"
                             v-on:click="selectUser(i,'copierSelectedIdx')">{{user.copierName}};
                        </div>
                        <input v-if="pageType=='edit'" class="pull-left copier" id="txtCopier"
                               style="width:100px"
                               type="text" @keyup.delete="deleteUser"/>
                    </div>
                </td>
            </tr>
            <tr v-if="purchase.main.copierReturnReason">
                <td class="td-title" style="width:16%;">抄送人驳回原因</td>
                <td colspan="5" style="text-align:left;">
                    <span class="sp-value">{{purchase.main.copierReturnReason}}</span>
                </td>
            </tr>
        </table>
        <!--采购信息-->
        <table class="table-detail no-print" style="border-top-width:0px;" v-if="type == 'buy' || purchase.main.buyerDate != ''">
            <tr>
                <td class=" td-module" colspan="4" style="background: yellow;">采购信息</td>
            </tr>
            <tr>
                <td class="td-title" style="width: 25%;">采购日期</td>
                <td>
                    <span style="padding-left: 4px;">{{purchase.main.buyerDate}}</span>
                </td>
                <td class="td-title" style="width: 25%;">采购人</td>
                <td>
                    <span style="text-align: left;padding-left: 4px;">{{purchase.main.buyerUserName}}</span>
                </td>
            </tr>
            <tr>
                <td class="td-title" style="width: 25%;">采购凭证</td>
                <td style="padding-bottom: 5px;" colspan="3">
                    <div class="divUploadedFiles"
                         style="padding-left: 8px;padding-top: 0px;padding-bottom: 0px;">
                        <div class="fj-tanzhongStyle" v-if="purchase.main.buyerAttachName"
                             style="width: 82%">
                            <b :class="fjStyle(purchase.main.buyerAttachName)"></b>
                            <div class="name" v-if="purchase.main.buyerAttachName" style="width:88%;"
                                 title="purchase.main.buyerAttachName">{{purchase.main.buyerAttachName}}
                            </div>
                            <div class="down"><a href="javascript:void(0)" class="nui-txt-link"
                                                 v-on:click="deleteFile">删除</a></div>
                        </div>
                        <div id="divUpload" style="width: 100px;float:right;width: 15%;">
                            添加附件
                        </div>
                    </div>
                </td>
            </tr>
        </table>
        <div class="south no-print" style="height:50px;line-height:50px;text-align:center;">
            <template v-if="type == 'add' || type == 'update' ">
                <input type="button" style="margin-left:20px;" value="草稿"
                       class="btn oaBtn btn-sm"
                       @click="save('-1')">
                 <input type="button" style="margin-left:20px;" value="提交"
                       class="btn btn-primary btn-sm"
                       @click="save('0')">
            </template>
            <template v-if="type == 'buy'">
                <input type="button" style="margin-left:20px;" value="草稿"
                       class="btn oaBtn btn-sm"
                       @click="updateBuyInfo('-1')">
                <input type="button" style="margin-left:20px;" value="提交"
                       class="btn btn-primary btn-sm"
                       @click="updateBuyInfo('0')">
            </template>
            <template v-if="currentUser.id==purchase.main.currentAuditorId && type == 'audit'">
                <input type="button" style="margin-left:20px;" value="通过"
                       class="btn oaBtn btn-sm"
                       @click="applyAudit('1')">
                <input type="button" style="margin-left:20px;" value="驳回"
                       class="btn oaBtn btn-sm"
                       @click="applyAudit('2')">
            </template>
        </div>
</div>
</div>
<script src="https://file.ggxqce.com/web/jquery-2.2.3.min.js"></script>
<!--插件JS-->
<script src="https://file.ggxqce.com/web/bootstrap.min.js"></script>
<!--框架已定义 JS-->
<script src="/dist/js/app_iframe.js?t=8e743a31"></script>
<!--oa自定义  JS-->
<script src="/dist/js/oa.js?t=54c6b89c"></script>
<script src="https://file.ggxqce.com/web/vue.min.js"></script>
<script type="text/javascript" src="/dist/plugins/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript" src="/dist/plugins/lhgdialog/lhgdialog.min.js?self=true"></script>
<script type="text/javascript" src="/dist/js/pages/common/commonService.js"></script>
<script src="/dist/plugins/webuploader-0.1.5/webuploader.min.js"></script>
<script type="text/javascript" src="/dist/js/pages/psi/inventory/class.js"></script>
<!--ztree组件所需js-->
<script type="text/javascript" src="/dist/plugins/ztree/js/jquery.ztree.all-3.5.min.js"></script>
<script type="text/javascript" src="/dist/plugins/ztree/js/jquery.ztree.exhide-3.5.js"></script>
<script type="text/javascript">
    var api = frameElement.api, W = api.opener;
    function refresh() {

    }
    var app = new Vue({
        el: '#app',
        data: {
            id: $.wyui.page.urlParams.id ? $.wyui.page.urlParams.id : '',
            pageType: $.wyui.page.urlParams.pageType,
            type: $.wyui.page.urlParams.type,
            isAdd: $.wyui.page.urlParams.isAdd,
            companyId: $.wyui.page.urlParams.companyId ? $.wyui.page.urlParams.companyId : getCurrentUser().companyId,
            currentUser: getCurrentUser(),
            purchaseList:[
                {value: '集团采购', name: '集团采购'},
                {value: '当地采购', name: '当地采购'},
            ],
            myGoodsList: [],
            purchase:{
                main:{
                    id:'',
                    applyDate:new Date().Format('yyyy-MM-dd'),
                    companyName: getCurrentUser().companyName,
                    companyId: getCurrentUser().companyId,
                    departId: getCurrentUser().departId,
                    departName: getCurrentUser().departName,
                    method:'',
                    requirements:'',
                    goodsId:'',
                    goodsName:'',
                    goodsSpec:'',
                    goodsUnit:'',
                    receiveDate:'',
                    purpose:'',
                    state:'-1',
                    count:'',
                    createUserId:getCurrentUser().id,
                    createUserName:getCurrentUser().name,
                    buyerUserId: '',
                    buyerUserName: '',
                    buyerDate: '',
                    buyerAttachName: '',
                    buyerAttachUrl: ''
                },
                goodsInfo:[
                    new Inventory.Goods()
                ],
                auditors:[
                    new Inventory.Audit(),
                    new Inventory.Audit()
                ],
                copiers: [],
                auditHistorys:[],
                attaches: []//图片
            },
            copierSelectedIdx: -1,
        },
        methods: {
            changeGoods:function (item) {
                var that=this;
                if(item.goodsName!=''){
                    for(var i=0;i<that.myGoodsList.length;i++){
                        if(item.goodsName==that.myGoodsList[i].goodsName){
                            item.id=that.myGoodsList[i].id;
                            item.price=that.myGoodsList[i].goodsUnitPrice;
                            item.unit=that.myGoodsList[i].goodsUnit;
                            item.requirements=that.myGoodsList[i].goodsDescription;
                            if(that.myGoodsList[i].goodsExtra){
                                item.extraList= JSON.parse(that.myGoodsList[i].goodsExtra);
                            }else{
                                item.extraList=[]
                            }
                        }
                    }
                }
            },
            hiddenDivModel: function () {
                $("#countyIdel").hide();
            },
            goBack: function () {
                api.close();
            },
            inputFocus: function (id) {
                $("#" + id).focus();
            },
            copierReturn: function () {
                var that = this;
                $.dialog({
                    content: 'url:/page/psi/inventoryCopierReturnReason.html?id='
                         + that.id + "&pageType=1" + "&t=" + new Date(),
                    title: '填写驳回原因',
                    width: 300,
                    height: 200,
                    max: false,
                    min: false,
                    lock: true
                });
            },
            addItem: function (prop, className) {
                this.purchase[prop].push(new Inventory[className]());
                setTimeout(function () {
                    initAutoComplete();
                }, 300);

            },
            delItem: function (prop, i, desc) {
                if (i == 0) {
                    alert("第一" + desc + "不能删除！")
                    return
                }
                if (this.purchase[prop].length <= 1) {
                    alert("请至少保留一件商品！")
                    return
                }
                this.purchase[prop].splice(i, 1);
            },
            showCopierReturn: function () {
                if (this.purchase.main.auditFlag == '0') {
                    var copierIds = new Array();
                    for (var i = 0; i < this.purchase.copiers.length; i++) {
                        copierIds.push(this.purchase.copiers[i].copierId);
                    }
                    return $.inArray(currentUser.id, copierIds) > -1;
                }
                return false;
            },
            deleteFile: function (i) {
                if (window.confirm("确定要删除该附件吗?")) {
                    this.purchase.attaches.splice(i, 1);
                }
            },
            download: function (attachId, fileName) {
                downloadFile(attachId,fileName)
                return false;
            },
            convertAuditFlagToName: function (auditFlag) {
                //auditFlag:-1,0,1,2,3,4,5,6
                switch (auditFlag) {
                    case "-1":
                        return "未提交";
                        break;
                    case "0":
                        return "审核中";
                        break;
                    case "1":
                        return "通过";
                        break;
                    case "2":
                        return "驳回";
                        break;
                    default :
                        break;
                }
            },
            goodsList: function () {
                var that = this;
                $.wyui.postMethod('/goods/getGoodsList.json',{companyId:that.companyId}, function (data) {
                        that.myGoodsList = data.records;
                        console.log(that.myGoodsList)
                    })
            },
            save: function (auditFlag) {
                var that = this;
                this.purchase.main.auditFlag = auditFlag;
                delete that.purchase.main.createTime;
                if (parseInt($.wyui.page.urlParams.isAdd) == 1) {
                    this.purchase.main.id = '';
                }
                for (var i = 0; i < that.myGoodsList.length; i++) {
                    for(var j = 0; j < that.purchase.goodsInfo.length; j++)
                        if (that.myGoodsList[i].goodsName == that.purchase.goodsInfo[j].goodsName) {
                            that.purchase.goodsInfo[j].goodsId = that.myGoodsList[i].id;
                        }
                }
                for(var i=0;i<that.purchase.goodsInfo.length;i++){
                    that.purchase.goodsInfo[i].extra=JSON.stringify(that.purchase.goodsInfo[i].extraList)
                }
                $.wyui.postMethod(urlConfig.psi.purchase.save, trimRN(this.purchase), function (data) {
                    alert("操作成功");
                    parent.refresh();
//                    var $iframe = top.findIframeByName("申购列表");
//                    $iframe[0].contentWindow.refresh();
                    api.close();
                });
            },
            updateBuyInfo:function (flag) {
                var that = this;
                var userId = getCurrentUser().id;
                var userName = getCurrentUser().name;
                var buyerDate = new Date().Format('yyyy-MM-dd');
                $.wyui.postMethod(urlConfig.psi.purchase.updateBuyInfo,
                    {id: that.purchase.main.id,
                        buyerUserId: currentUser.id,
                        buyerUserName: currentUser.name,
                        buyerDate: new Date().Format('yyyy-MM-dd'),
                        attachName: that.purchase.main.buyerAttachName,
                        attachUrl: that.purchase.main.buyerAttachUrl
                    },
                function (data) {
                    alert("操作成功");
                    parent.refresh();
                    api.close();
                });
            },
            applyAudit: function (auditFlag) {
                if (auditFlag == "2") {

                } else {
                    if (!confirm("确定要通过吗？")) {
                        return;
                    }
                }
                var that = this;
                var advise = '';
                for (var i = 0; i < this.purchase.auditors.length; i++) {
                    if (this.purchase.auditors[i].auditorId == this.currentUser.id) {
                        advise = this.purchase.auditors[i].auditAdvise;
                        break;
                    }
                }
                if (auditFlag == '2' ) {
                    this.copierReturn(1)
                    return;
                }
                if (advise == "") {
                    advise = "同意！";
                }
                $.wyui.postMethod(urlConfig.psi.purchase.applyAudit, {
                    id: that.purchase.main.id,
                    userId: getCurrentUser().id,
                    userName:getCurrentUser().name,
                    roleName:getCurrentUser().roleName,
                    auditFlag: auditFlag,
                    advise: advise
                }, function () {
                    alert("审核成功");

                        parent.refresh();

//                    if (top.findTabPanelByName("申购列表")) {
//                        var $iframe = top.findIframeByName("申购列表");
//                        $iframe[0].contentWindow.refresh();
//                    }
                    api.close();
                });
            },
            goBack: function () {
                api.close();
            },
            showDatePicker: function (e) {
                var that = this;
                WdatePicker({
                    onpicked: function (dp) {
                        that.purchase.main.receiveDate = dp.cal.getNewDateStr();
                        return true;
                    },
                });
                $(e.target).blur();
            },
            inputFocus: function (id) {
                $("#" + id).focus();
            },
            selectUser: function (i, prop) {
                this.copierSelectedIdx = -1;
                this[prop] = i;
            },
            unselectUser: function () {
                this.copierSelectedIdx = -1;
            },
            deleteUser: function (event) {
                if (event.keyCode == 46 || event.keyCode == 8 && event.target.value == "") {
                    if (this.copierSelectedIdx > -1) {
                        this.purchase.copiers.splice(this.copierSelectedIdx, 1);
                        this.copierSelectedIdx = -1;
                    } else {
                        this.copierSelectedIdx = this.purchase.copiers.length - 1;
                    }
                }
            },
            fjStyle: function (fjName) {
                if (fjName) {
                    var type = fjName.substring(fjName.lastIndexOf('.') + 1);
                    return 'img fj-' + type
                }
                return 'img'
            },
            download: function (attachId, fileName) {
                if (attachId != null && attachId != "") {
                    var data = {
                        attachId: attachId,
                        fileName: fileName
                    }
                    prompt(JSON.stringify(data))
                }
//                $('#ifAttach').attr('src', server.ip + '/attach/downloadFile.json?fileUrl=' + attachId + '&fileName=' + fileName);
//                return false;
            },
            init:function () {
                var that = this;
                this.uploader = WebUploader.create({
                    // 选完文件后，是否自动上传。
                    auto: true,
                    // swf文件路径
                    swf: "/statics/plugin/webuploader-0.1.5/Uploader.swf",
                    // 文件接收服务端。
                    server: server.fjIp + "/attach/uploadFile.json",
                    // 选择文件的按钮。可选。
                    // 内部根据当前运行是创建，可能是input元素，也可能是flash.
                    pick: '#divUpload',
                    duplicate: true
                });
                this.uploader.on("uploadStart", function () {
                    $("#progress").show();
                });
                this.uploader.on("uploadComplete", function () {
                    $("#progress").hide();
                });
               /* // 文件上传成功，给item添加成功class, 用样式标记上传成功。
                this.uploader.on('uploadSuccess', function (file, response) {
                    if (response._raw == "文件上传出错！") {
                        alert("文件上传出错！");
                    } else {
                        that.purchase.attaches.push({
                            id: response.id,
                            name: response.name,
                            url: response.url
                        });
                    }
                });*/
                // 文件上传成功，给item添加成功class, 用样式标记上传成功。
                this.uploader.on('uploadSuccess', function (file, response) {
                    that.purchase.main.buyerAttachName = response.name;
                    that.purchase.main.buyerAttachUrl = response.url;
                });
                // 文件上传失败，显示上传出错。
                this.uploader.on('uploadError', function (file) {
                    alert("上传失败！");
                });
            }
        },
        mounted: function () {
            var that = this;
            //编辑
            if (parseInt($.wyui.page.urlParams.id) > 0) {
                $.wyui.postMethod(urlConfig.psi.purchase.getPurchaseById, {id: $.wyui.page.urlParams.id}, function (data) {
                    /*var params = {moduleId: data.main.id};
                    commonService.getAttachesByModuleId(params, function (attaches) {
                        if (attaches) {
                            data.attaches = attaches;
                        }
                        that.purchase = data;
                    });*/
                    console.log(data)
                    for(var i = 0 ;i < data.goodsInfo.length;i++){
                        if(data.goodsInfo[i].extra) {
                            data.goodsInfo[i].extraList = JSON.parse(data.goodsInfo[i].extra);
                        }else{
                            data.goodsInfo[i].extraList=[];
                        }
                    }
                    that.purchase = data;
                    if(that.type == 'buy' ){
                        that.purchase.main.buyerUserName = currentUser.name;
                        that.purchase.main.buyerDate = new Date().Format('yyyy-MM-dd');
                    }
                    console.log(that.purchase)
                });
            } else {
                $.wyui.postMethod(urlConfig.system.user.getFirstParent, {userId: getCurrentUser().id}, function (data) {
                    app.purchase.auditors[0].auditorId = data.id;
                    app.purchase.auditors[0].auditorName = data.roleName + "-" + data.name;
                });
            }
            that.goodsList();
            that.init();
        }
    });
</script>
<script>
    $('[contenteditable]').each(function () {
        // 干掉IE http之类地址自动加链接
        try {
            document.execCommand("AutoUrlDetect", false, false);
        } catch (e) {
        }

        $(this).on('paste', function (e) {
            e.preventDefault();
            var text = null;

            if (window.clipboardData && clipboardData.setData) {
                // IE
                text = window.clipboardData.getData('text');
            } else {
                text = (e.originalEvent || e).clipboardData.getData('text/plain') || prompt('在这里输入文本');
            }
            if (document.body.createTextRange) {
                if (document.selection) {
                    textRange = document.selection.createRange();
                } else if (window.getSelection) {
                    sel = window.getSelection();
                    var range = sel.getRangeAt(0);

                    // 创建临时元素，使得TextRange可以移动到正确的位置
                    var tempEl = document.createElement("span");
                    tempEl.innerHTML = "&#FEFF;";
                    range.deleteContents();
                    range.insertNode(tempEl);
                    textRange = document.body.createTextRange();
                    textRange.moveToElementText(tempEl);
                    tempEl.parentNode.removeChild(tempEl);
                }
                textRange.text = text;
                textRange.collapse(false);
                textRange.select();
            } else {
                // Chrome之类浏览器
                document.execCommand("insertText", false, text);
            }
        });
        // 去除Crtl+b/Ctrl+i/Ctrl+u等快捷键
        $(this).on('keydown', function (e) {
            // e.metaKey for mac
            if (e.ctrlKey || e.metaKey) {
                switch (e.keyCode) {
                    case 66: //ctrl+B or ctrl+b
                    case 98:
                    case 73: //ctrl+I or ctrl+i
                    case 105:
                    case 85: //ctrl+U or ctrl+u
                    case 117: {
                        e.preventDefault();
                        break;
                    }
                }
            }
        });
    });
</script>
<script>
    $(function () {
        initAutoComplete();
    });

    function initAutoComplete() {
        $(".auditorName,.copier").autoComplete({
            url: server.ip + urlConfig.system.user.getTop10ByNameUser,
            render: function (users, panel) {
                for (var i = 0; i < users.length; i++) {
                    $("<li></li>").data("autoComplete",
                        users[i]).html("<a>" + users[i].name + "&nbsp;&nbsp;&nbsp;" +
                        "(" + "&nbsp;" + users[i].companyName + "-" + users[i].departName + "-" + users[i].roleName + "&nbsp;" + ") " + "</a>")
                        .appendTo(panel);
                }
            },
            selected: function (user) {
                if ($(this).hasClass("auditorName")) {
                    var idx = $(this).attr("idx");
                    app.purchase.auditors[idx].auditorId = user.id;
                    app.purchase.auditors[idx].auditorName = user.roleName + "-" + user.name;
                } else if ($(this).hasClass("copier")) {
                    var userIds = new Array();
                    for (var i = 0; i < app.purchase.auditors.length; i++) {
                        userIds.push(app.purchase.auditors[i].auditorId);
                    }
                    for (var i = 0; i < app.purchase.copiers.length; i++) {
                        userIds.push(app.purchase.copiers[i].copierId);
                    }
                    if ($.inArray(user.id, userIds) == -1) {
                        app.purchase.copiers.push({copierId: user.id, copierName: user.name});
                    } else {
                        alert("审核人、抄送人不能重复输入");
                    }
                    $(this).val("");
                }
                return false;
            },
            height: 210,
            width: 300
        });
    }
</script>
</body>
</html>